import React, { useEffect, useState } from 'react';
import { Button, message } from 'antd';
import an58 from '@mmstudio/an000058';
import { Message as M1, Result as R1 } from '../api/introduction/query.api';
import { Message as M2, Result as R2 } from '../api/introduction/publish.api';
import RichEditor from '../../components/richeditor';
import Title from './title';
import api from '../../atoms/api';
import Maintain from './maintain';


export default function Content() {
	const [desc, setdesc] = useState('');
	useEffect(() => {
		void (async () => {
			const res = await an58<R1, M1>(api['/api/introduction/query'], 'get');
			setdesc(res.desc);
		})();
	}, []);
	return <>
		<Title />

		<div className='s01'>
			<Button shape='round' type='primary' onClick={async () => {
				const ret = await an58<R2, M2>(api['/api/introduction/publish'], 'post',
					{
						content: desc
					});
				if (ret.ok === true) {
					message.success('发布成功');
				} else {
					message.error('发布失败');
				}
			}} >发布</Button>{ }
		</div>
		<Maintain />
		<RichEditor value={desc} onChange={(c) => {
			setdesc(c);
		}} />
		<style jsx>{`
.s01{
display: flex;
flex-direction: row-reverse;
}


`}</style>
	</>;
}

